package org.example.Thread01;

public class Dome_Thread11 {
    public static void main(String[] args) {
        //定义一个阻塞队列
        MyBlockingQueue queue=new MyBlockingQueue(100);
        //
        Thread producer = new Thread(()->{
            int num=0;
            while(true){
                try {
                    queue.put(num);
                    System.out.println("生产了元素："+num);
                    num++;
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        //启动
        producer.start();
        //定义一个消费者线程
        Thread consumer = new Thread(()->{
            while(true){
                try {
                    Integer value=queue.take();
                    System.out.println("消费了元素："+value);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        //启动消费者线程
        consumer.start();
    }
}
